package 曾世昌12_9.zuoye5;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.text.SimpleDateFormat;
import java.util.List;

public class demo {
    public static void main(String[] args) throws Exception {
        SAXReader saxReader = new SAXReader();
        Document read = saxReader.read( "E:\\untitled5\\src\\mxdx3\\day6\\zuoye5\\book.xml" );
        Element rootElement = read.getRootElement();
        List<Element> book = rootElement.elements( "book" );
        SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" );
        for (Element element : book) {
            if (Integer.parseInt( element.attributeValue( "id" ) ) >= 2) {
                System.out.println( element.attributeValue( "id" ) + "," +
                        element.elementText( "title" ) + "," +
                        element.elementText( "publishDate" ) + "," +
                        element.elementText( "price" ) );
            }
        }
        System.out.println( "====================================================" );
        for (Element element : book) {
            if (element.elementText( "title" ).contains( "Java" )) {
                System.out.println( element.attributeValue( "id" ) + "," +
                        element.elementText( "title" ) + "," +
                        element.elementText( "publishDate" ) + "," +
                        element.elementText( "price" ) );
            }
        }
        System.out.println( "====================================================" );
        for (Element element : book) {
            if (Integer.parseInt( element.elementText( "price" ) ) > 50) {
                System.out.println( element.attributeValue( "id" ) + "," +
                        element.elementText( "title" ) + "," +
                        element.elementText( "publishDate" ) + "," +
                        element.elementText( "price" ) );
            }
        }
    }
}
